package com.tamo.ppresta.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tamo.ppresta.R;
import com.tamo.ppresta.bean.GetRecommendItemsBean;
import com.tamo.ppresta.bean.GetReconmmendAppsBean;
import com.tamo.ppresta.util.LogUtils;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
 * @author yeyang
 * @name ppresta
 * @class name：com.tamo.ppresta.adapter
 * @class describe
 * @time 2022/12/27 20:15
 * @change
 * @chang time
 * @class describe
 */
public class HomeAdapter extends BaseQuickAdapter<GetRecommendItemsBean.RecommendItemsEntity, BaseViewHolder> {

    private ArrayList<GetRecommendItemsBean.RecommendItemsEntity> mRecommendItemsEntity = new ArrayList<>();
    private ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> mApps = new ArrayList<>();
    private Boolean isFootView = false;//是否添加了FootView

    public HomeAdapter(int layoutResId, ArrayList<GetRecommendItemsBean.RecommendItemsEntity> recommendItemsEntity) {
        super(layoutResId, recommendItemsEntity);
        mRecommendItemsEntity = recommendItemsEntity;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, GetRecommendItemsBean.RecommendItemsEntity itemsEntity) {
        LogUtils.info("convert: ", baseViewHolder.getLayoutPosition() + "");
        if (baseViewHolder.getLayoutPosition() <= mRecommendItemsEntity.size()) {
            if (itemsEntity.getProductLogoUrl() != null) {
                ImageView ivItemIcon = baseViewHolder.findView(R.id.iv_item_icon);
                Glide.with(getContext()).load(itemsEntity.getProductLogoUrl()).into(ivItemIcon);
            }
            if (!itemsEntity.getProductName().isEmpty()) {
                baseViewHolder.setText(R.id.tv_item_title, itemsEntity.getProductName());
            }
            baseViewHolder.setText(R.id.tv_item_jine, "$" + itemsEntity.getMaxAmount());
            baseViewHolder.setText(R.id.tv_item_baifen, itemsEntity.getInterestRate());
            baseViewHolder.setText(R.id.tv_item_date, itemsEntity.getFastPassDay());
            TextView tvItemState = baseViewHolder.findView(R.id.tv_item_state);
            switch (itemsEntity.getUserStatus()) {
                case 0:
                case 1:
                case 9:
                    tvItemState.setText("去借款");
                    tvItemState.setBackgroundResource(R.drawable.login_normal_bg);
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    tvItemState.setText("审核中");
                    tvItemState.setBackgroundResource(R.drawable.login_normal_bg);
                    break;
                case 7:
                case 8:
                case 10:
                    tvItemState.setText("去还款");
                    tvItemState.setBackgroundResource(R.drawable.bottom_red_bg);
                    break;
            }
        } else {
            LogUtils.info("convert: ", "第二种布局");
        }
    }

    public ArrayList<GetRecommendItemsBean.RecommendItemsEntity> getRecommendItemsEntity() {
        return mRecommendItemsEntity;
    }

    public void setRecommendItemsEntity(ArrayList<GetRecommendItemsBean.RecommendItemsEntity> recommendItemsEntity) {
        mRecommendItemsEntity = recommendItemsEntity;
    }

    public ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> getApps() {
        return mApps;
    }

    public void setApps(boolean isFoot, ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> apps) {
        mApps = apps;
    }
}